home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lanutsrc.zip / NBOUNCE.C < prev    next >
Text File  |  1991-03-13  |  5KB  |  169 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <direct.h>
  6. #include <conio.h>
  7.  
  8. #include "lantasti.h"
  9.  
  10. #define DOS 0x21
  11. #define NETBIOS 0x5C
  12. #define DELIM "+, "
  13.  
  14. /* structure to allow easy access to both segment and offset portions of
  15.    far pointers */
  16. #define LIST_SIZE 50
  17. #define NAME_SIZE 20
  18. typedef struct LIST {
  19.     int  num_servers;
  20.     char server[LIST_SIZE][NAME_SIZE];
  21.        } LIST;  
  22.  
  23. /* definitions to save typing time */
  24. #define C_SERVER list->server[i % list->num_servers]
  25.  
  26. struct SEGOFFS {
  27.   unsigned offs;
  28.   unsigned seg;
  29. };
  30.  
  31. typedef union POINTER {
  32.   unsigned char *ptr;
  33.   struct SEGOFFS l;
  34. } POINTER;        
  35.  
  36. /***********************************************************************
  37.  Delete leading and trailing blanks.
  38. ***********************************************************************/
  39. void dltb(string)
  40.   char *string;
  41. {
  42.   int i;
  43.  
  44.   i  = strspn(string, " ");
  45.  
  46.   if (i) strcpy(string,string + i);
  47.  
  48.   i = strlen(string) - 1;
  49.   while (i && (string[i] == ' ')) {
  50.     string[i--] = '\0';
  51.   }
  52. }
  53.  
  54. /* getstring ********************************************************************
  55.  Get a string from the console -- takes a pointer to a string buffer, the 
  56.  longest permissible length and two switches. The empty switch determines
  57.  whether or not the user is allowed to enter an empty string. If TRUE, he
  58.  can, if FALSE, he must enter something.  The shown switch determines 
  59.  whether or not input is echoed to the screen, TRUE if echoed, FALSE if
  60.  invisible
  61. *****************************************************************************/
  62. void getstring(prompt,buffer,length,empty,shown) 
  63.   char *prompt,*buffer;
  64.   int length,empty,shown;
  65. {
  66.   fprintf(stdout,"%s",prompt);
  67.   fgets(buffer,length,stdin);
  68.   if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  69.   while (!(strlen(buffer) || empty)) {
  70.     fprintf(stdout,"%s",prompt);
  71.     fgets(buffer,length,stdin);
  72.     if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
  73.   }
  74. }
  75.  
  76. /* error ********************************************************************
  77. Traps for system errors and prints a happy message.
  78. *****************************************************************************/
  79. void error(code,message)
  80.   int code;
  81.   char *message;
  82. {
  83.   char *ptr;
  84.   
  85.   if (code) {
  86.     ptr = get_error_text(code);
  87.     puts(ptr);
  88.   }
  89.   else puts(message);
  90. }
  91.  
  92. /* net_send  *****************************************************************
  93. Breaks apart the names and checks them against the list of logged in folks.
  94. Prints its answer.
  95. *****************************************************************************/
  96. int net_send(dest,message,type)
  97.   char *dest;
  98.   char *message;
  99.   int type;
  100. {
  101.   struct msg_buffer msg;
  102.   struct SREGS segregs;
  103.   union REGS registers;
  104.   union POINTER ptr;
  105.  
  106.   strcpy(msg.text,message);  
  107.   strcpy(msg.destination,strupr(dest));
  108.   strcpy(msg.server,"");
  109.   strcpy(msg.user,"");
  110.   msg.type = type;
  111.   ptr.ptr = (char *) &msg;
  112.   
  113.   segregs.ds = ptr.l.seg;
  114.   registers.x.si = ptr.l.offs;
  115.   registers.x.ax = 0x5f98;
  116.   
  117.   intdosx(®isters,®isters,&segregs);
  118. }
  119.  
  120. /* main ********************************************************************
  121.  
  122. *****************************************************************************/
  123. int main(argc,argv)
  124.   int argc;
  125.   char *argv[];
  126. {
  127.   union REGS regs;
  128.   int msgflag;
  129.   char string[80];
  130.  
  131.   puts("NBOUNCE utility for LANtastic -- Copyright 1990 by SoftMagic, Inc.");
  132.   puts("All rights reserved.");
  133.   puts("Thanks for trying this slightly dangerous BETA TEST VERSION!!\n");
  134.   
  135.   if (argc < 3) {
  136.     puts("Usage: NBOUNCE <machines> <server>");
  137.     puts("  Logs off all machines meeting the given specification from the");
  138.     puts("  given server.  The '*' in the machine name list means all users");
  139.     puts("  logged onto the given server");  
  140.     puts("  Note that you must run the SoftMagic Resident Extension Module");
  141.     puts("  (RXM.COM) on all the machines that you intend to control remotely.");
  142.     exit(0);
  143.   }  
  144.   
  145. /* get the current message state (it winds up in regs.h.dl) */
  146.   regs.x.ax = 0x5F9A;
  147.   intdos(®s,®s);
  148.   msgflag = regs.h.dl;
  149.   
  150. /* don't beep or pop while we're doing this */
  151.   regs.x.ax = 0x5F9B;
  152.   regs.h.dl = 0;
  153.   intdos(®s,®s); 
  154.  
  155. /* send the net bounce message */
  156.   if (argv[1][0] == '*') argv[1][0] = 0;
  157.   
  158.   string[0] = 0;
  159.   if (argv[2][0] != '\\') strcat(string,"\\\\");
  160.   strcat(string,argv[2]); 
  161.  
  162.   net_send(argv[1],string,0x80);
  163.   
  164. /* restore message flag */
  165.   regs.x.ax = 0x5F9B;
  166.   regs.h.dl = msgflag;
  167.   intdos(®s,®s); 
  168. }
  169.